package com.yxw.live_vod_backend_boot.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * mqtt客户端消息处理类
 *
 * @author qlinc
 */
@Slf4j
@Component
public class MqttMessageHandle implements MessageHandler {


    @Override
    public void handleMessage(Message<?> message) throws MessagingException {       
        try {
            String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
            String data = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
            log.info("消息主题:{},收到订阅消息:{},接收的Packet数据{}", topic, message, data);
            if (topic.startsWith("")){
                log.info("推送循环提醒消息开始。。。");
            }
        } catch (Exception e) {
            log.error("mqtt客户端消息处理类异常:{}", e.getStackTrace());
            e.printStackTrace();
        }
    }
}

